<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('课程信息列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>课程名称：</label>
                            <input type="text" name="courseName"/>
                        </li>
                        <li>
                            <label>年度：</label>
                            <input type="text" name="courseYear"/>
                        </li>
                        <li>
                            <label>是否结课：</label>
                            <select name="isCourseEnd" th:with="type=${@dict.getType('cws_course_yes_no')}">
                                <option value=""></option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>上/下学期：</label>
                            <select name="isUp" th:with="type=${@dict.getType('cws_up_down_term')}">
                                <option value=""></option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="cws:course:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.editTab()"
               shiro:hasPermission="cws:course:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="cws:course:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="cws:course:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('cws:course:edit')}]];
    var removeFlag = [[${@permission.hasPermi('cws:course:remove')}]];
    var endClazzFlag = [[${@permission.hasPermi('cws:course:end')}]];
    var startResitFlag = [[${@permission.hasPermi('cws:course:resit')}]];
    var datas = [[${@dict.getType('cws_course_type')}]];
    var prefix = ctx + "cws/course";
    var resitPrefix = ctx + "cws/resit";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "课程信息",
            columns: [{
                checkbox: true
            },
                {
                    field: 'courseId',
                    title: '',
                    visible: false
                },
                {
                    field: 'courseName',
                    title: '课程名称'
                },
                {
                    field: 'teacherName',
                    title: '教师'
                },
                {
                    field: 'clazzName',
                    title: '班级'
                },
                {
                    field: 'courseYear',
                    title: '年度'
                },
                {
                    field: 'isCourseEnd',
                    title: '是否结课',
                    align: 'center'
                },
                // {
                //     field: 'courseType',
                //     title: '选修课/必修课',
                //     align: 'center',
                //     formatter: function (value, row, index) {
                //         return $.table.selectDictLabel(datas, value);
                //     }
                // },
                {
                    field: 'isUp',
                    title: '上/下学期',
                    align: 'center'
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs ' + endClazzFlag + '" href="javascript:void(0)" onclick="endClazz(\'' + row.courseId + '\' , \'' + row.courseName + '\')"><i class="fa fa-edit"></i>结课</a> ');
                        actions.push('<a class="btn btn-info btn-xs ' + startResitFlag + '" href="javascript:void(0)" onclick="startResit(\'' + row.courseId + '\', \'' + row.courseName + '\')"><i class="fa fa-warning"></i>补考</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.courseId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.courseId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function endClazz(courseId, courseName) {
        $.modal.confirm("确定完结此课程“" + courseName + "”吗？", function () {
            $.ajax({
                type: "post",
                url: prefix + "/edit",
                data: {"courseId": courseId, "isCourseEnd": "是"},
                dataType: 'json',
                success: function (result) {
                    $.modal.alertSuccess(result.msg);
                    $.table.refresh();
                },
                error: function (result) {
                    $.modal.alertWarning(result.msg);
                }
            })
        });
    }

    function startResit(courseId, courseName) {
        $.modal.open("补考"+courseName, resitPrefix + "/add/"+courseId);
    }
</script>
</body>
</html>